package com.lgj.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Jdbc {
    public static void main(String[] args) throws Exception{
//        //注册驱动
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        //获取连接
//        Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.2.115:3306/javaWeb", "root", "123456@lgj123.");
//        //获取执行者连接
//        Statement statement = connection.createStatement();
//        //执行sql语句并接受结果
//        String sql = "select * from user";
//        ResultSet rs = statement.executeQuery(sql);
//        //处理结果
//        while(rs.next()){
//            System.out.println(rs.getInt("id")+"\t"+rs.getString("name"));
//        }
//        connection.close();
//        statement.close();



        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.2.115:3306/javaWeb", "root", "123456@lgj123.");
        Statement statement = connection.createStatement();
        String sql = "select * from user";
        ResultSet res = statement.executeQuery(sql);
        while(res.next()){
            System.out.println(res.getString("id")+"\t"+res.getString("name")+"\t"+res.getString("age"));
        }
    }
}
